<?php
class MyApp
{
	public $site;
	public $controllerName;
	public $actionName;
	
	public function dispatching()
	{
		$scriptName = $_SERVER['REQUEST_URI'];
		$scriptName = substr($scriptName, 1, strpos($scriptName . '?', '?')-1);
		@list($controllerName, $actionName) = explode('/', $scriptName);
		if(empty($controllerName)){
			$controllerName = 'index';
		}
		if(empty($actionName)){
			$actionName = 'index';
		}
		
		$this->site['host'] = $_SERVER['HTTP_HOST'];
		$this->controllerName = $controllerName;
		$this->viewName = $actionName;
		
		$filename = "{$controllerName}_controller.php";
		$className = 'controller_' . $controllerName;
		$controller = new $className($this);
		if($controller->existsAction($actionName . 'Action')){
			$response = $controller->execute($actionName);
			return $response;
		}else{
			throw new Exception('action invalid!', 1);
		}
		
	}
}